<?php

namespace app\admin\model;

use think\Model;
use think\Db;

class User extends Model

{
  function changeState($state,$acc){
    return $result = $this -> where('acc', $acc)->update(['state' => $state]);
  }

  function edit($acc,$nickname,$pwd,$desc,$phone,$address){
    return $result = $this -> where('acc', $acc)->update(['nickname' => $nickname,'pwd' => $pwd,'desc' => $desc,'phone' => $phone,'address' => $address]);
  }

  function search($newSearchWord){
    $sql = "";
    for($i=0;$i<count($newSearchWord);$i++) {
      if($i==0){
        $sql .="SELECT * FROM gjc_user WHERE CONCAT(nickname) LIKE '%$newSearchWord[0]%' OR CONCAT(nickname) LIKE '%$newSearchWord[0]%'";
      }else{
        $sql .=" UNION SELECT * FROM gjc_user WHERE CONCAT(nickname) LIKE '%$newSearchWord[$i]%' OR CONCAT(nickname) LIKE '%$newSearchWord[$i]%'";
      }
    }
    return $result = $this->query($sql);
  }

}


